
#ifndef   __FIFO_BUFFER__H__
#define   __FIFO_BUFFER__H__

#define   ENTRY_MESSAGE_READ				0
#define   ENTRY_MESSAGE_SET_AS_READ		1

typedef struct _FIFO_INF
{
		int pWrite;
		int pRead;
		int BufferSize;
		int AvailabelEntryCount;
		unsigned char* FifoBuffer;
}FIFO_INF;

/* typedef struct _FIFO_ENTRY */
/* {		 */
/* 		FIFO_INF fifo; */
/* 		int AvailabelEntryCount; */
/* }FIFO_ENTRY; */


void Fifo_Init(FIFO_INF* fi, unsigned char* FifoBuffer, int BufferSize);

/* return - bytes number put into fifo or (-1) if no place to write */
int Fifo_Write(FIFO_INF* fi, unsigned char* DataBuffer, unsigned int ByteCount);

int Fifo_i_Write(FIFO_INF* fi, unsigned char* DataBuffer, unsigned int ByteCount);

/* Read from FifoBuffer to DataBuffer; return - numbers of bytes was put to DataBuffer */
int Fifo_Read(FIFO_INF* fi, unsigned char* DataBuffer);

/* Read from FifoBuffer to DataBuffer number of ByteToRead; return - numbers of bytes was put to DataBuffer */
int Fifo_nRead(FIFO_INF* fi, unsigned char* DataBuffer, unsigned int ByteToRead);

int Fifo_AvailableToWrite(FIFO_INF* fi);

int Fifo_AvailableToRead(FIFO_INF* fi);


/* ENTRYs - management of messages(entrys) queue */
/* each ENTRY - ending with '0' like string */

/* read one Entry; return - byte amount counted with zero '0' */
int Fifo_Entry_Read(FIFO_INF* fi, unsigned char* DataBuffer);

/* interrupt using for;  */
int Fifo_Entry_i_Puts(FIFO_INF* fi, unsigned char* DataBuffer, unsigned int ByteCount);
int Fifo_Entry_i_PutCh(FIFO_INF* fi, unsigned char Ch);

/* return - pointer on the available Entry; if MessageStatus = 1, do the Entry as read 
and return pointer on the next Entry, if the next message is available or NULL if not*/
unsigned char* Fifo_Entry_Get(FIFO_INF* fi, int MessageStatus);

#endif


